﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WyUnity.Data;
using WyUnity.Data.Query;
using WyUnity.Data.TableMapper;

namespace UnitTest.DA_Test
{
    [TestClass]
    public class ReadSingleTable
    {
        [Map("t_ItemClass")]
        public class ItemClass : TableBase<ItemClass>
        {
            [Map("FItemClassID")]
            public int ClassID { get; set; }

            [Map("FName")]
            public string Name { get; set; }
            [Map("FType")]
            public int Type { get; set; }

            public static FieldBase pClassID = new Field<ItemClass>(p => p.ClassID);
            public static FieldBase pName = new Field<ItemClass>(p => p.Name);
            public static FieldBase pType = new Field<ItemClass>(p => p.Type);
        }
        [TestMethod]
        public void QueryList()
        {
            using (var db = DB.OpenSession())
            {
                Console.WriteLine(db.QueryList<ItemClass>().Count());
            }
        }
        [TestMethod]
        public void QueryListWithCondition()
        {
            using (var db = DB.OpenSession())
            {
                Console.WriteLine(db.QueryList<ItemClass>(ItemClass.pClassID < 100).Count());
            }
        }

        [TestMethod]
        public void SmallIntToInt()
        {
            using (var db = DB.OpenSession())
            {
                Assert.AreEqual(db.QueryFirstOrDefault<ItemClass>(ItemClass.pType == 1).Type, 1);
            }
        }
    }
}
